//
//  DateSelctViewController.m
//  RONGAO
//
//  Created by wei wang on 2017/3/16.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "DateSelctViewController.h"
#import "Event.h"
#import "CoustomSelctViewController.h"
#import "EventListViewController.h"

@interface DateSelctViewController ()<UITableViewDataSource,UITableViewDelegate>

/** tableView **/
@property(nonatomic,strong) UITableView *tableView;

/** array **/
@property(nonatomic,strong) NSArray *array;

@end

@implementation DateSelctViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationStyle];
    [self masLayoutSubview];
    self.array = @[@"1小时内",@"6小时内",@"12小时内",@"过去七天内",@"自定义"];
    
}



- (void)setNavigationStyle{
    
    [self setNavigationTitle:@"视频搜索" titleColor:[UIColor colorWithRed:210/255.0 green:177/255.0 blue:104/255.0 alpha:1]];
    [self setLeftButtonImage:[UIImage imageNamed:@"icon_back_nor"]];
    
}

#pragma mark - tableView Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.array.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 54;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
    
}


#pragma mark - tableView Delegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.textLabel.textColor = [UIColor colorWithHexString:@"#56504f"];
        [cell.textLabel setFont:[UIFont systemFontOfSize:15.f]];
        
    }
    

    
    
    cell.textLabel.text = self.array[indexPath.row];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
    cell.backgroundColor = [UIColor whiteColor];
    cell.accessoryView = image;
    if (indexPath.row == 4) {
        
        image.contentMode = UIViewContentModeScaleAspectFit;
        image.image = [UIImage imageNamed:@"icon_more_nor"];
        
    }
    else{
        
        image.image = [UIImage imageNamed:@"video_set_bg_nor"];

    }
    
    
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row != 4) {
        
        UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        cell.backgroundColor = [UIColor whiteColor];
        cell.accessoryView = image;
        image.image = [UIImage imageNamed:@"video_set_bg_sel"];
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 4) {
        
        CoustomSelctViewController *customVC = [CoustomSelctViewController new];
        
        for (UIViewController *vc in self.navigationController.viewControllers) {
            if ([vc isKindOfClass:[EventListViewController class]]) {
                customVC.delegate = (EventListViewController *)vc;
                break;
            }
        }
        
        [self.navigationController pushViewController:customVC animated:YES];
        
        
    }else{
        
        if (self.TimeEvent) {
            
            self.TimeEvent(indexPath.row);
        }
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}


- (UITableView *)tableView{
    
    if (!_tableView) {
        
        __weak UIView *superView = self.view;
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        [superView addSubview:_tableView];
        //        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;//隐藏tableView的分割线
        //        _tableView.scrollEnabled = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
    }
    
    return _tableView;
    
}

- (void)masLayoutSubview{
    
    __weak UIView *superView = self.view;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
      
        make.edges.mas_equalTo(superView);
        
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
